package com.example.administrator.orchardeveryday.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.orchardeveryday.R;
import com.example.administrator.orchardeveryday.bean.FruitBaikeEntity;
import com.example.administrator.orchardeveryday.bean.FruitFriendsEntity;
import com.example.administrator.orchardeveryday.bean.FruitMain;
import com.example.administrator.orchardeveryday.utils.ImageLoaderHelper;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by Administrator on 15-10-23.
 */
public class FruitFriendsLvAdapter extends AppBaseAdapter<FruitMain>{
    DisplayImageOptions displayImage;
    public FruitFriendsLvAdapter(List<FruitMain> list, Context context) {
        super(list, context);
        displayImage = ImageLoaderHelper.getDisplayImageLoader();
    }

    @Override
    public ViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
        FruitMain main=list.get(position);
        ViewHolder vh=ViewHolder.get(context,convertView,parent, R.layout.item_fruit_friends_listview);
        ImageView face= (ImageView) vh.findViewById(R.id.item_fruit_friends_lv_face);
        TextView name= (TextView) vh.findViewById(R.id.item_fruit_friends_lv_username);
        ImageView rank= (ImageView) vh.findViewById(R.id.item_fruit_friends_lv_userrank);
        TextView ctime= (TextView) vh.findViewById(R.id.item_fruit_friends_lv_ctime);
        TextView description= (TextView) vh.findViewById(R.id.item_fruit_friends_lv_description);
        TextView worth= (TextView) vh.findViewById(R.id.item_fruit_friends_lv_worth);
        TextView comment= (TextView) vh.findViewById(R.id.item_fruit_friends_lv_comment);
        ImageLoader.getInstance().displayImage(list.get(position).getData().getUserface(), face, displayImage);
        name.setText(list.get(position).getData().getUsername());
        switch (Integer.parseInt(list.get(position).getData().getUserrank()))
        {
            case 0:
                rank.setImageResource(R.mipmap.v0_s_rect);
                break;
            case 1:
                rank.setImageResource(R.mipmap.v1_s_rect);
                break;
            case 2:
                rank.setImageResource(R.mipmap.v2_s_rect);
                break;
            case 3:
                rank.setImageResource(R.mipmap.v3_s_rect);
                break;
            case 4:
                rank.setImageResource(R.mipmap.v4_s_rect);
                break;
            case 5:
                rank.setImageResource(R.mipmap.v5_s_rect);
                break;
        }
        int time=list.get(position).getData().getStime()-list.get(position).getData().getCtime();
        String commentTime="";
        if(time/60<60)
        {
            commentTime=time/60+"分钟前";
        }
        else
        {
            if(time/60/24<24)
            {
                commentTime=time/60/24+"小时前";
            }
            else
            {
                SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日");
                long x=  System.currentTimeMillis()-time*1000;
                commentTime=format.format(x);
            }
        }
        ctime.setText(commentTime);
        description.setText(list.get(position).getData().getDescription());
        worth.setText(list.get(position).getData().getWorth_num()+"");
        comment.setText(list.get(position).getData().getComment_num()+"");
        return vh;
    }
}
